package com.hmjk.health.util;

public class reminderTime{
	public static final int MON = 1;
	public static final int TUE = 2;
	public static final int WEN = 4;
	public static final int THR = 8;
	public static final int FRI = 16;
	public static final int SAT = 32;
	public static final int SUN = 64;
	public static final int WEEK_MARK = 128;
	public static final int SINGLE_MARK = 255;
	

	
    public int info = 0;  //1, befor dawn,2 limosis 3 after breakfast 4 before lunch 5 after lunch 6 befor dinner 
                      // 7 after dinner 8 before bed  0 none
	public int Hour; //0~23
	public int Min; //0~59	
	public int repeat = WEEK_MARK;	//bit 
	public int single = SINGLE_MARK;  // bit   bit位为1相应的星期为每次 0 为单次
	
	
	public void setWeekRepeat(int weekinfo, boolean isOn, boolean isOnlyOne)  //week 0~6
	{
		if(isOn)
		 repeat = repeat | (1<< weekinfo);
		else
		 repeat = repeat & (~(1 << weekinfo));
		
		if(!isOnlyOne)
			single = single | (1<< weekinfo);
			else
			single = single & (~(1 << weekinfo));		
	}
	
	public boolean getWeekRepeat(int weekinfo)  //week 0~6
	{
		boolean isOn;
		int tmp = repeat & (1<< (weekinfo));
		if(tmp != 0)
			isOn = true;
		else 
			isOn = false;
		
		return isOn;
	}	
	
	public boolean getWeekSingle(int weekinfo)  //week 0~6
	{
		boolean isSingle;
		int tmp = single & (1<< (weekinfo));

		if(tmp != 0)
			isSingle = false;
		else
			isSingle = true;	
		
		return isSingle;
	}		
	
	private String to2HexStr(int n)
	{
		n = n%256;
		if(n>15)
		 return Integer.toHexString(n);
		else
		{
			String s = "0"+Integer.toHexString(n);
			return s;
		}
	}
	
	public String getHexStr()
	{
		String s;
		s = to2HexStr(info)+to2HexStr(Min)+to2HexStr(Hour)+to2HexStr(repeat)+to2HexStr(single);
		return s;
	}
	
	public void setByHexStr(String s)
	{
		char tmp[] = new char[2];
		s.getChars(0, 2, tmp, 0);
		String s1 = new String(tmp);
		s1 = new String(tmp);
		int i = Integer.parseInt (s1, 16);
		info = i;	
		
		s.getChars(2, 4, tmp, 0);
		s1 = new String(tmp);
		i = Integer.parseInt (s1, 16);
		Min = i;	
		
		s.getChars(4, 6, tmp, 0);
		s1 = new String(tmp);
		i = Integer.parseInt (s1, 16);
		Hour = i;	
		
		s.getChars(6, 8, tmp, 0);
		s1 = new String(tmp);
		i = Integer.parseInt (s1, 16);
		repeat = i;
		
		s.getChars(8, 10, tmp, 0);
		s1 = new String(tmp);
		i = Integer.parseInt (s1, 16);
		single = i;		
	}
	
	public reminderTime(int i,int min, int hour,int r)
	{
		info = i;
		Min = min;
		Hour = hour;
		repeat = r;
	}
	
	public reminderTime()
	{
		info = 0;
		Min = -1;
		Hour = -1;
		repeat = WEEK_MARK;
	}
			
	public reminderTime(String s)
	{
       this.setByHexStr(s);
	}

	public int getInfo()
	{
		return info;
	}	
	
	public int getM()
	{
		return Min;
	}
	
	public int getH()
	{
		return Hour;
	}
	
	public int getR()
	{
		return repeat;
	}		
}
